import React from 'react';
import {BrowserRouter as Router,Route,Switch,Redirect} from 'react-router-dom'
import Home from './View/Home'
import Login from './View/Login'
import Empty from './View/Empty'
import 'antd/dist/antd.css';


const PrivateRoute=({component:Com,...rest})=>{
 
    return <Route {...rest} render={({location})=>{
        const islogin=localStorage.getItem('isLogin');
        if(islogin==='true'){
            return <Com /> 
        }else{
            return <Redirect to={{pathname:'/', state:location.pathname}}/>
        }
    }}/>
}


const App = () => {

    localStorage.setItem('isLogin','false');
  
    return (
        // <Router>
        //     <Route path='/home' component={Home}></Route>
        // </Router>
        
        <Router>
            <Switch>
                <Route exact path='/' render={(props) => {
                    return <Redirect to="/login"></Redirect>
                }}/>
                <PrivateRoute path='/home'  component={Home}/>
                <Route path="/login" component={Login}></Route>
                
                <Route component={Empty}></Route>
            </Switch>
        </Router>
    )
}


export default App
